/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package babydisco.Math;

import java.util.ArrayList;

/**
 *  Masterclass voor wiskunde gedoe, zorg dat de GUI alleen deze aanroept
 *  En dat deze de rest regelt.
 * @author Florian
 */
public class MasterClass {
    public Fourier fourier;
    public Wavelet wavelet;
    public ArrayList<Fourier> intervals;
    private ArrayList<Double> input; //input data of measured voltages over time
    private double sampleFreq; // sample frequenty of the input
    private int sampleSize;
    private int intervalLength; //length of an interval, just choose this
                                    //in such a way that the total interval
                                    // has a length of a power of two

    private void setInput(ArrayList<Double> input){
        this.input = input;
    }

    private void setSampleFreq(double freq){
        this.sampleFreq = freq;
    }

    public double getFreq(){return sampleFreq;}
    public ArrayList<Double> getInput(){return input;}

    public MasterClass( ArrayList<Double> input, double f){
        sampleSize = input.size();
        this.input = input;
        sampleFreq = f;
    }

    public void makeFourierIntervals(){
        ArrayList<Double> inputtemp = new ArrayList<Double>();
        int current=0;
        while(current <= sampleSize-current){
            for(int i = 0; i<intervalLength;i++){
                inputtemp.add(input.get(current+i));
            }
            intervals.add(new Fourier(inputtemp, sampleFreq));
            inputtemp.clear();
            current+=intervalLength;
        }
    }

    /**
     * make the fourier over the whole time
     */
    public void makeFourierWholeTime(){
            fourier = new Fourier(powerOfTwo(), sampleFreq);
    }

    /**
     * make the input list into a thing of length power of Two
     * for fourier
     */
    public ArrayList<Double> powerOfTwo(){
        int sampleSizeT = 1;
        int N= input.size();
        ArrayList<Double> inputTemp = new ArrayList<Double>();
        while(sampleSizeT < N){
            sampleSizeT*=2;
        }
        if(sampleSizeT >N)
            sampleSizeT /=2;
        for(int i = 0;i<sampleSizeT;i++){
            inputTemp.add(input.get(i));
        }
        return inputTemp;
    }


}
